#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXSIZE 100
typedef struct{
	int data[MAXSIZE];
	int front;
	int rear;
}queue;

void initqueue(queue *q)
{
	q->front=0;
	q->rear=0;
}

int isempty(queue *q)
{
	return q->front==q->rear;
}

int isfull(queue *q)
{
	return (q->rear+1)%MAXSIZE==q->front; 
}

void inqueue(queue *q,int v)
{
	if(isfull(q))
	{
		return ;
	}
	q->data[q->rear]=v;
	q->rear=(q->rear+1)%MAXSIZE;
}

void buildqueue(queue *q)
{
	int num;
	char m;
	while(scanf("%d%c",&num,&m)==2)
	{
		inqueue(q,num);
		if(m=='\n')
		{
			break;
		}
	}
}

void findsum(queue *q,int t)
{
	int front=q->front;
	int rear=(q->rear-1+MAXSIZE)%MAXSIZE;
	while(front!=rear)
	{
		int sum=q->data[front]+q->data[rear];
		if(sum==t)
		{
			printf("%d %d\n",q->data[front],q->data[rear]);
			return ;
		}
		else if(sum<t)
		{
			front=(front+1)%MAXSIZE;
		}
		else
		{
			rear=(rear-1+MAXSIZE)%MAXSIZE;
		}
	}
}

int main()
{
	queue q;
	initqueue(&q);
	buildqueue(&q);
	int sum;
	scanf("%d",&sum);
	findsum(&q,sum);
	return 0; 
}

